;
;	>> PigXLs - Stage 2 <<
;
;	A 128 bytes intro for the Atari 800 XL (c) 2010-09-12 by JAC!
;	Stage 2: Lores mode with index addressing and scaled coordinates, color based on index and $d01f sound
;
;	Created using WUDSN IDE. Visit http://www.wudsn.com to increase my hit counter.

;	IOCB commands
open	= $03
close	= $0c
plot	= $09
draw	= $11
fill	= $12

iocom	= $342	;Command
ioadr	= $344	;Address
icaux1	= $034A	;Auxilary 1
icaux2	= $034B	;Auxilary 2
ciov	= $e456	;CIO vector

rowcrs	= $54	;Row of cursor, 1 byte
colcrs	= $55	;Column of cursor, 2 bytes

color	= $2fb	;Color for graphics operations

*	= $2000

start	ldx #'S		;Instead of string definition "S:",$9B
 	stx $00
	ldx #$60	;Channel 6
	lda #open	;Set open command
	sta iocom,x
	asl		;Graphics 2*3 = 6
	sta icaux2,x	;icaus1,x is already 0

loop 	jsr ciov	;Leaves a and x unchanged, returns y=1
dodraw 	lda #draw	;Set draw command
	sta iocom,x
count	ldy #0
	bne nofirst	;Leave color black for first line starting at (0,0)
	tya
nofirst	sta color
	inc count+1 
 	lda pigx,y	;Random column
	sta colcrs
 	lda pigy,y
 	sta rowcrs
stop	bne loop

effloop
	ldx 20
effloopx
	txa
	and #31
	cmp #16
	bcc *+4
	eor #31

	sta $d40a
	sta $d016
	sta $d01f

	lda $d40b
	beq effloop
	asl
	bpl *+4
	eor #$ff
	sta $d01a
	inx
	bvc effloopx
end

xoffset	= 0
xscale	= 2
yoffset = 0
yscale	= 2

pigx	.byte [48-xoffset]/xscale,[45-xoffset]/xscale, [67-xoffset]/xscale, [184-xoffset]/xscale, [194-xoffset]/xscale
	.byte [208-xoffset]/xscale, [226-xoffset]/xscale, [233-xoffset]/xscale, [252-xoffset]/xscale, [282-xoffset]/xscale
	.byte [234-xoffset]/xscale, [158-xoffset]/xscale, [139-xoffset]/xscale, [147-xoffset]/xscale, [136-xoffset]/xscale
	.byte [86-xoffset]/xscale, [117-xoffset]/xscale, [108-xoffset]/xscale, [71-xoffset]/xscale, [48-xoffset]/xscale
pigy	.byte [88-yoffset]/yscale, [135-yoffset]/yscale, [125-yoffset]/yscale, [157-yoffset]/yscale, [177-yoffset]/yscale
	.byte [181-yoffset]/yscale, [157-yoffset]/yscale, [171-yoffset]/yscale, [175-yoffset]/yscale, [107-yoffset]/yscale
	.byte [39-yoffset]/yscale, [57-yoffset]/yscale, [43-yoffset]/yscale, [63-yoffset]/yscale, [71-yoffset]/yscale
	.byte [51-yoffset]/yscale, [77-yoffset]/yscale, [91-yoffset]/yscale, [105-yoffset]/yscale, [93-yoffset]/yscale

;*	= $2e0
;	.word start
